<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>isSameOrigin</title>
</head>

<body>
    <script>
        const isSameOrigin = (origin, destination) =>
            origin.protocol === destination.protocol && origin.host === destination.host;
        const urlPro = 'https://eveningwater.com/my-web-projects/';
        const urlHome = 'https://eveningwater.com/my-web-projects/home/';
        const urlMoz = 'https://developer.mozilla.org';
        const origin = new URL(urlPro);
        const destination = new URL(urlHome);
        console.log(isSameOrigin(origin, destination));; // true
        const other = new URL(urlMoz);
        console.log(isSameOrigin(origin, other));; // false
        document.writeln(`${urlPro}与${urlHome}${isSameOrigin(origin, destination) ? '' : '不'}是同源地址，<br/>${urlPro}与${urlMoz}${isSameOrigin(origin, other) ? '' : '不'}是同源地址!`)
    </script>
</body>

</html>